pp108 : Process Platform WS-AppServer Model Plug-in

Process Platform WS-AppServer Model Plug-in

The Process Platform WS-Apps Model plug-in is extended from the Process Platform Model plug-in. This enables the Process Platform WS-AppServer integration with the HTML5SDK. Refer to Process Platform Model Plug-in and Using WS-AppServer Business Logic in XForms for more information on the Process Platform Model plug-in and on the Process Platform WS-AppServer integration respectively. It is not a part of the HTML5SDK and must be included in the code to use it.

Settings

To use the plug-in in a new instance, it must be created in your Web page with appropriate settings and must include method names and namespaces for the operations. The following properties can be passed as settings to the cordys.model.wsapps plug-in while creating an instance:

Setting

Description

Default Value

objectName

Name of the objects in the structure received in the response, which will be a part of the model

 

isReadOnly

Option to specify if the model is read-only. It is automatically set to false, if you specify at least one of the insert, update, or delete settings. You can modify this behavior by specifying a value.

true

namespace

Namespace of the methods to be called by the model for read, update, insert, or delete operations. You can specify different values for different operations, if required.

 

useTupleProtocol

Boolean value that specifies if the model must use Tuple Protocol. You can set this to false if the Web service method used by the model does not use the Process Platform Tuple Protocol.
If the value is set to true, then the model uses the Process Platform Tuple Protocol for all the insert, update, and delete operations.

true

read

Set of properties used in the read operation

 

create

Set of properties used in the create operation

 

update

Set of properties used in the update operation

 

delete

Set of properties used in the delete operation

 

defaults

Default set of parameters for the read, create, update, and delete methods

 

fields

Set of properties defining a template structure of the objects used in the model. Refer to Fields Attribute on this page for more information.

 
wsapps Set of parameters for enabling the access mode and auto initialization. Refer to Enabling WS-AppServer Integration on this page for more information.  

Note: Settings can be specified at various levels. To set some of these settings and make them applicable to all the instances in a page, you must set them for the $.cordys.model.defaults collection. Settings specific to a model can be set for the collection used in the creation of the model. This overrides the values set for the $.cordys.model.defaults collection. You can also specify the settings when you call the read, create, update, and delete methods, which again overrides the values set when you created the model.

Properties

Property

Value

<objectName>

KO Observable array consisting the collection of the Observable business objects. <objectName> refers to the name of your business object. Therefore, if your business object is called Order, then this will be myModel.Order. You can use this to call APIs of the Observable array such as destroy, which marks the object for deletion.

Methods

The following methods are supported by the cordys.model.ws-apps plug-in in addition to the cordys.model plug-in methods:

Method

Description

read(options)

Sends a request to retrieve the objects using properties specified in the read property in the settings. Refer to the Properties for Read operation section for more information.

addBusinessObject(object)

Adds a new Object. It is wrapped into a KO Observable, which is returned. This object contains the access mode information, possible options and initial values if defined. These are treated as new Objects and will be sent over in the next create or synchronize call for creation.

validate(object)

Used to check the constraint violation and access mode information. This also returns the possible options for a field.

Enabling WS-AppServer Integration

WS-AppServer integration is enabled in the WS-AppServer model plug-in by specifying the following properties in the WS-AppServer settings:

Setting Property Description
wsapps checkAccessControl

Enables the access control for fields

  initializeDefaults Provides the initial values for fields

Example:

WS-Apps Properties
var orderModel = new $.cordys.model.wsapps({ 
                    objectName:"Orders",
                    wsapps: {
                        checkAccessControl: "1",
                        initializeDefaults: "1"
                    }
                });

Field properties for reading the possible options

The following properties are required for a field to obtain the possible options:

Property

Description

name

Name of the field in the object. If this property is unavailable, an empty field will be created in the object to avoid binding problems that may occur if the field does not exist in the object.

getPossibleValues

Boolean value to specify whether to obtain the possible values if specified in the WS-AppServer Package

getPossibleValuesPerRecord

Boolean value to specify whether to obtain the possible values for all the records if specified in the WS-AppServer Package. This is specific to Read method.

Example for defining fields
var orderModel = new $.cordys.model({
                    objectName:"Orders",
                    fields:[ "CustomerID", "RequiredDate", "OrderDate", "ShipppedDate",
                        {
                            name: "EmployeeID",
                            getPossibleValues: "true", // needed for addBusinessObject method
                            getPossibleValuesPerRecord: "true" //needed for read method
                        }
                    ]
                })

Properties for Read operation

The following properties are an extension of the standard jQuery.ajax options:

Property

Description

method

Name of the method to be invoked

namespace

Namespace of the method to be invoked

parameters

Parameters of the method to be called, which can be one of the following:

  • An object with key or value pairs
  • An array of objects with name and value pairs. Each value can be either a string or a function returning a string.
  • A function returning an XML string
  • An XML string
  • Cursor: The cursor determines the size of the data set to return and the position to start from
    Cursor takes the following properties:
    • position: The start position of the data set to return results from. For example, when set to 5, the initial 5 results will be ignored.
    • numRows: The number of rows to fetch from the data set. For example, when set to 5 only, 5 objects starting at position will be returned.
    • maxRows: The maximum number of rows to expect will be ignored.
      Refer to Implementing Pagination for more information on using cursors.

Examples

The following is the sample code snippet for creating a WS-Apps model for handling the orders from the Northwind database:

var orderModel = new $.cordys.model.wsapps({
                    objectName: "Orders",
                    isReadOnly: false,
                    defaults: {
                        namespace: "http://schemas.cordys.com/Northwind"
                    },
                    read: {
                        method: "GetOrdersObjects",
                        parameters: {
                            "fromOrderID": "10248",
                            "toOrderID": "10249"
                        }
                    },
                    fields: [{
                        name: "EmployeeID",
                        getPossibleValues: "true",
                        getPossibleValuesPerRecord: "true"
                        },
                        "RequiredDate", "OrderID", "ShippedDate", "ShipVia", "Freight", "ShipName", "ShipAddress", "ShipCity",
                        "ShipRegion", "ShipPostalCode"
                    ],
                    wsapps: {
                        checkAccessControl: "1",
                        initializeDefaults: "1"
                    }
                }); 

Using the WS-Apps response

  • Access Values: You can get the access values by OrderID['@access']().
Access Values
 
<input type="text" id="fldOrderID" data-bind="value:OrderID.text, enable: OrderID['@access']() != 'r'"/>
  • Possible values: You can get the possible values by ordersModel.Orders.getPossibleValues().
Possible Values
<select id="fldEmployeeID" data-bind="options:orderModel.Orders.getPossibleValues('EmployeeID'),optionsText:'label',optionsValue:'value', value: EmployeeID.text()">
</select>